package greed;
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/lhp2v5/
//现需要将一根长为正整数 bamboo_len 的竹子砍为若干段，每段长度均为正整数。请返回每段竹子长度的最大乘积是多少。
//(1) 当所有绳段长度相等时，乘积最大。(2) 最优的绳段长度为3
public class LCR_131砍竹子1 {
    static public int cuttingBamboo(int bamboo_len) {
        if(bamboo_len <= 3) return bamboo_len - 1;
        int a = bamboo_len / 3;
        int b = bamboo_len % 3;
        if(b == 0) return (int) Math.pow(3,a);
        if(b == 1) return (int) Math.pow(3,a-1) * 4;
        return (int) Math.pow(3,a) * 2;
    }
    public static void main(String[] args) {
        System.out.println(cuttingBamboo(12));


    }
}
